package com.zhuzi.demo.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.zhuzi.demo.exception.MyException;
import com.zhuzi.demo.service.UserService;

@RestController
@RequestMapping(value = "/user")
public class UserController extends BaseController{
	@Autowired
    private UserService userService;

    @RequestMapping("/add")
    public ModelAndView addUser(String userName,String password,String phone)throws MyException{
    	Map<String,Object> map = userService.addUser(userName,password,phone);
    	return returnMav(map);
    }

    @RequestMapping("/all")
    public ModelAndView findAllUser(@RequestParam(name = "pageNum",required=false,defaultValue="1")int pageNum,@RequestParam(name="pageSize",required=false,defaultValue="10")int pageSize)throws MyException{
        PageHelper.startPage(pageNum,pageSize);
        Map<String,Object> map =  userService.findAllUser(pageNum,pageSize);
        return returnMav(map);
    }
}